package org.example.computerdesign.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.computerdesign.common.enums.HttpCode;
import org.example.computerdesign.exception.ServiceException;

/**
 * 统一返回体
 * @author 朱文权
 * */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RespBody<T> {
    /**
     * 返回信息
     * */
    private String msg;
    /**
     * 返回状态码
     * */
    private Integer code;
    /**
     * 返回数据
     * */
    private T data;

    public static RespBody<?> success(){
        return new RespBody<>(HttpCode.SUCCESS.getMsg(), HttpCode.SUCCESS.getCode(), null);
    }
    public static<T> RespBody<T> success(T data){
        return new RespBody<>(HttpCode.SUCCESS.getMsg(),HttpCode.SUCCESS.getCode(), data);
    }
    public static RespBody<?> fail(ServiceException e){
        return new RespBody<>(e.getMessage(),e.getCode(),null);
    }
    public static RespBody<?> fail(String msg,Integer code){
        return new RespBody<>(msg,code,null);

    }



}
